package logic

import (
	"api/internal/svc"
	"api/internal/types"
	"api/model/businessprofile"
	"api/service"
	"api/utils"
	"context"
	"github.com/zeromicro/go-zero/core/stores/sqlx"

	"github.com/zeromicro/go-zero/core/logx"
)

type BusProfileLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewBusProfileLogic(ctx context.Context, svcCtx *svc.ServiceContext) *BusProfileLogic {
	return &BusProfileLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *BusProfileLogic) BusProfile(req *types.RequestBusProfile) (resp *types.ResponseMsg, err error) {
	conn := sqlx.NewMysql(l.svcCtx.Config.DataSource)
	busProfileModel := businessprofile.NewBusinessProfileModel(conn)
	busProfileModel.Insert(l.ctx, &businessprofile.BusinessProfile{
		ShopName:   req.ShopName,
		Mobile:     req.Mobile,
		Account:    req.Account,
		Bank:       req.Bank,
		BankBranch: req.BankBranch,
		CaFront:    req.CaFront,
		CaBack:     req.CaBack,
		BusImg:     req.BusImg,
		Address:    req.Address,
		Longitude:  req.Longitude,
		Latitude:   req.Latitude,
		OutsideImg: req.OutsideImg,
		InsideImg:  req.InsideImg,
		CreateAt:   utils.GetCurDateTime(),
	})

	return service.ReturnOk()
}
